/*
 * @Author: SingleBiu
 * @Date: 2021-12-01 21:45:52
 * @LastEditors: SingleBiu
 * @LastEditTime: 2021-12-01 22:04:19
 * @Description: file content
 */
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int thread_count;

void *hello(void *rank);

int main(int argc, const *argv[])
{
    long thread;
    pthread_t *thread_handles;

    thread_count = strtol(argv[1], NULL, 10);

    thread_handles = malloc(thread_count * sizeof(pthread_t));

    for (thread = 0; thread < thread_count; thread++)
    {
        pthread_create(&thread_handles[thread], NULL, &hello, (void *)thread);
    }

    printf("Hello from main process\n");

    for (thread = 0; thread < thread_count; thread++)
    {
        pthread_join(thread_handles[thread],NULL);
    }

    free(thread_handles);

    return 0;
}

void* hello(void* rank)
{
    long my_rank = rank;

    printf("Hello from thread %ld of %d\n",my_rank,thread_count);

    return NULL;
}
